﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http.Results;
using Newtonsoft.Json;

namespace WebApi
{
    public class Common
    {
        private static Common _common;
        private static Object _object= new object();

        public static Common GetInstince()
        {
            if (_common == null)
            {
                lock (_object)
                {
                    if (_common == null)
                    {
                        _common=new Common();
                    }
                }
            }
            return _common;
        }


        public HttpResponseMessage ToJsonResult(object list)
        {

            var str= JsonConvert.SerializeObject(list);
            HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") };
            return result; 
             
        }

    }

    public class BaseResult
    {
        /// <summary>
        /// 结果代码 Sucess：成功 Fail：失败
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 错误信息
        /// </summary>
        public string Message { get; set; }
    }


    public class ResultMessage<T> : BaseResult
    {
        public T Data { get; set; }

        public IEnumerable<T> DatList { get; set; }

        public BaseQuery PaddingInfo { get; set; }
    }


    public class BaseQuery
    {
        /// <summary>
        /// 当前页码
        /// </summary>
        public int PageIndex { get; set; }
        /// <summary>
        /// 每页大小
        /// </summary>
        public int PageSize { get; set; }
        /// <summary>
        /// 总记录数
        /// </summary>
        public int PageCount { get; set; }
    }

    public enum Status
    {

        Sucess=0,
        Fail=1,
    }

}
